package service;

import dao.UserMapper;
import org.apache.ibatis.session.SqlSession;
import pojo.User;
import utils.MyBatisUtils;

public class LoginService {
    public User login(User user){
        SqlSession session = MyBatisUtils.openSession();
        System.out.println("执行service");
        UserMapper mapper = session.getMapper(UserMapper.class);
        User findUser = mapper.findUserByNameAndPassword(user);
        return findUser;
    }
    public boolean register(User user){
        SqlSession session = MyBatisUtils.openSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        int result = mapper.addUser(user);
        if(result==1){
        MyBatisUtils.commitAndClose(session);
            return true;
        }else {
        MyBatisUtils.commitAndClose(session);
            return false;
        }
    }
}
